//
//  QYTransgerLandCell.m
//  QingYue
//
//  Created by Zheng on 2017/6/14.
//  Copyright © 2017年 com.lanou.product_A. All rights reserved.
//

#import "QYTransgerLandCell.h"
#import "QYTransferLendModel.h"

@implementation QYTransgerLandCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLbl];
        
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.top.equalTo(self).offset(5);
            make.height.mas_equalTo(40);
        }];
        
        
    }
    return self;
}

- (void)setModel:(QYTransferLendModel *)model {
    _model = model;

    
    if (_quickBuilder) {
        _quickBuilder = nil;
    }
    
    if (_formView) {
        [_formView removeFromSuperview];
        _formView = nil;
    }
    
    _titleLbl.text = _model.bookName;
    
    _quickBuilder = [[KWFormViewQuickBuilder alloc] init];
    [_quickBuilder addRecord:@[@"条码号",_model.properthID]];
    [_quickBuilder addRecord:@[@"借阅人",_model.borrowName1]];
    [_quickBuilder addRecord:@[@"出借人",_model.borrowName2]];
    [_quickBuilder addRecord:@[@"转借日期",_model.borrowTime]];

    
    _formView = [_quickBuilder startCreatWithWidths:@[@((MSSize_Width-40)/3),@((MSSize_Width-40)/3*2)] startPoint:CGPointMake(20, 45)];
    
    [self.contentView addSubview:_formView];
    
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = Font(17);
        
    }
    return _titleLbl;
}


- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, 1);
    CGContextMoveToPoint(context, 24, 229);
    CGContextAddLineToPoint(context, MSSize_Width-24, 229);
    CGContextSetLineDash(context, 0, (CGFloat[]){3,1}, 2);
    CGContextDrawPath(context, kCGPathStroke);
}

@end
